from django import template
from datetime import datetime
from django.utils.timezone import now as aware_now,localtime
from utils.datetime_paser import str_to_datetime


register = template.Library()


@register.filter
def time_format(value):
    if isinstance(value,str):
        try:
            value = str_to_datetime(value)
        except:
            return value
    elif isinstance(value,datetime):
        pass
    else:
        return value

    return localtime(value).strftime('%Y-%m-%d %H:%M:%S')